/*
 * Login.java
 *
 * Created on 05/11/2011, 16:19:12
 */
package GUI;

import FMK_SEK.Base.SecurityFramework;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author mj
 */
public class Login extends javax.swing.JFrame {

    public Login() {
        initComponents();
        this.setResizable(false);
        this.rootPane.setDefaultButton(btnAceptar);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel6 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtContrasena = new javax.swing.JPasswordField();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(GUI.AgendaApp.class).getContext().getResourceMap(Login.class);
        setTitle(resourceMap.getString("FormLogin.title")); // NOI18N
        setForeground(resourceMap.getColor("FormLogin.foreground")); // NOI18N
        setMinimumSize(new java.awt.Dimension(250, 88));
        setName("FormLogin"); // NOI18N
        setResizable(false);

        jPanel6.setMinimumSize(new java.awt.Dimension(100, 138));
        jPanel6.setName("jPanel6"); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setPreferredSize(new java.awt.Dimension(128, 128));
        jPanel5.setLayout(new java.awt.BorderLayout());

        jLabel3.setIcon(resourceMap.getIcon("jLabel3.icon")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jPanel5.add(jLabel3, java.awt.BorderLayout.CENTER);

        jPanel6.add(jPanel5);

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        jPanel3.add(jLabel2);

        txtContrasena.setText(resourceMap.getString("txtContrasena.text")); // NOI18N
        txtContrasena.setMinimumSize(new java.awt.Dimension(240, 24));
        txtContrasena.setName("txtContrasena"); // NOI18N
        txtContrasena.setPreferredSize(new java.awt.Dimension(240, 24));
        jPanel3.add(txtContrasena);

        jPanel1.add(jPanel3, java.awt.BorderLayout.PAGE_END);

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jPanel2.add(jLabel1);

        txtUsuario.setText(resourceMap.getString("txtUsuario.text")); // NOI18N
        txtUsuario.setMinimumSize(new java.awt.Dimension(240, 24));
        txtUsuario.setName("txtUsuario"); // NOI18N
        txtUsuario.setPreferredSize(new java.awt.Dimension(240, 24));
        jPanel2.add(txtUsuario);

        jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_START);

        jPanel6.add(jPanel1);

        getContentPane().add(jPanel6, java.awt.BorderLayout.CENTER);

        jPanel4.setBorder(null);
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new java.awt.GridBagLayout());

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(GUI.AgendaApp.class).getContext().getActionMap(Login.class, this);
        btnAceptar.setAction(actionMap.get("botonAceptar")); // NOI18N
        btnAceptar.setActionCommand(resourceMap.getString("btnAceptar.actionCommand")); // NOI18N
        btnAceptar.setName("btnAceptar"); // NOI18N
        jPanel4.add(btnAceptar, new java.awt.GridBagConstraints());

        btnCancelar.setAction(actionMap.get("quit")); // NOI18N
        btnCancelar.setDefaultCapable(false);
        btnCancelar.setName("btnCancelar"); // NOI18N
        jPanel4.add(btnCancelar, new java.awt.GridBagConstraints());

        getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Login().setVisible(true);
            }
        });
    }

    @Action
    public void botonAceptar() {
        if (SecurityFramework.getInstance().intentarLogin(txtUsuario.getText(), String.valueOf(txtContrasena.getPassword()))) {
            AgendaApp.getApplication().mostrarPrincipal();
            this.setVisible(false);
            this.dispose();
        } else {
            JOptionPane.showMessageDialog(null, "Nombre de usuario o contraseña incorrectos.");
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPasswordField txtContrasena;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}
